//
//@File    :	16.2_strfile.cpp
//@Time    :	2022/03/25 16:53:42
//@Auther  :	Sun Sheng
//@Contact :	970340843@qq.com
//@Desc    :	read strings from a file
//

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>

int main()
{
    using namespace std;
    ifstream fin;
    fin.open("tobuy.txt");
    if (fin.is_open()==false)
    {
        cerr<<"Can't open  file. Bye.\n";
        exit(EXIT_FAILURE);
    }
    string item;
    int count=0;
    getline(fin,item,':');
    while (fin)
    {
        ++count;
        cout<<count<<": "<<item<<endl;
        getline(fin,item,':');
    }
    cout<<"Done\n";
    fin.close();
    system("pause");
    return 0;
}